# vim:ts=4:sw=4:noet:
""" User interface state management """

import os
import pickle
from c.base.version import InfoStrings
from c.base.platform import Platform

SAVE_STATE_FILE = Platform.getConfigFilePath(InfoStrings["configfile"])

class UISaveState:
	def __init__(self):
		self.sdict = {}
		if os.path.exists(SAVE_STATE_FILE):
			f = file(SAVE_STATE_FILE, "rb")
			self.sdict = pickle.load(f)
			f.close()

	def setOpt(self, n, v):
		self.sdict[n] = v

	def getOpt(self, n, ifNot=None):
		if n in self.sdict:
			return self.sdict[n]
		else:
			return ifNot

	def save(self):
		f = file(SAVE_STATE_FILE, "wb")
		pickle.dump(self.sdict, f, 2)
		f.close()

